package stringtest;
import org.junit.Test;

/**
 * @Author: fxy
 * @Date: 2022/02/21/14:28
 * @Description:
 * 通过字面量赋值的字符串，存储在堆空间的字符串常量池中
 */
public class StringTest1 {
    @Test
    public void test1() {
        //字面量定义的方式，“abc"存储在字符串常量池中
        String s1 = "abc";
        String s2 = "abc";
        s1 = "hello";
        System.out.println(s1==s2);
    }

    @Test
    public void test2() {
        //字面量定义的方式，“abc"存储在字符串常量池中
        String s1 = "abc";
        String s2 = "abc";
        s2+="def";
        System.out.println(s1==s2);
    }

    @Test
    public void test3() {
        //字面量定义的方式，“abc"存储在字符串常量池中
        String s1 = "abc";
        String s2 = s1.replace('a','m');

        String s3 = new String("abc");
        String s4 = s3.replace('a','m');
        System.out.println(s1==s2);
        System.out.println(s3==s4);
    }
}
